<?php
	//includes
	require_once 'includes.php';
	
	$startTime = microtime() + time();
	
	$wineCom = new WinesCom();
	$products = $wineCom->GetSavedWineURLs($_GET['offset'], $_GET['number']);
//	$urls = $wineCom->GetUncrawledWineURLs();
	
	$result = array('success' => 0, 'fail' => 0);
	
	//saves wines
	foreach ($products as $url)
	{
		//wine item
		$wineItem = $wineCom->GetWineItem($url['url']);
		
		//if null
		if ($wineItem == null) continue;
		
		//wine id
		$wineItem->id = $url['id'];
		
		//saves the beer into DB
		$saveResult = $wineItem->Save();
		
		//stats
		if ($saveResult)
		{
			$result['success']++;
		}
		else 
		{
			$result['fail']++;
		}		
	}

	$endTime = microtime() + time();
	
	//totals
	$resultTime = $endTime - $startTime;
	echo "Total time: $resultTime; Success: {$result['success']}; Fail: {$result['fail']}; ";		
	
?>